import {Component, OnInit, Input, OnChanges} from '@angular/core';
import * as echarts from 'echarts';
import {NzMessageService} from "ng-zorro-antd";
import {FetchService} from "../../../core/net/fetch.service";
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';

@Component({
  selector: "app-weather-panel",
  templateUrl: "./weather-panel.component.html",
  styleUrls: ['../dispatch-common.scss', './weather-panel.component.scss']
})
export class WeatherPanelComponent implements OnInit {
  effect = 'scrollx';
  weatherData = [];
  warningData = [];
  modalShow = false;
  nzBodyStyle: any = {
    padding: '10px'
  };


  qxModalShow = false;
    iframeSrc: SafeResourceUrl;
    weatherInfo: string;
    temperatureInfo;
  constructor(
    private message: NzMessageService,
    private sanitizer: DomSanitizer,
    private fetchService: FetchService,
  ) {
  }

  ngOnInit() {
    // this.fetchService.post<any>('schedule/wrsActualDispatchApply/weather', {}).subscribe(res => {
    //   this.weatherData = res.weather.map(item => {
    //     const info = item.info;
    //     let weatherText1 = '';
    //     let weatherText2 = '';
    //     if (info.includes('-')) {
    //       weatherText1 = info.split('-')[0];
    //       weatherText2 = info.split('-')[1];
    //     } else {
    //       weatherText1 = info;
    //     }
    //     return {
    //       date: item.date,
    //       area: item.area,
    //       rain: item.rain,
    //       aqi: item.aqi,
    //       humidity: item.humidity,
    //       tempature: item.tempature,
    //       info: item.info,
    //       wind: item.wind,
    //       level: item.level,
    //       highTemp: item.hignLower.split('/')[0],
    //       lowTemp: item.hignLower.split('/')[1],
    //       weatherText1: weatherText1,
    //       weatherText2: weatherText2
    //     };
    //   });
    //
    //   this.warningData = res.warning.map(item => {
    //     return {
    //       title: item['信息标题'],
    //       subTitle: item['信息正文'].split(':')[0],
    //       content: item['信息正文'].split(':')[1],
    //     };
    //   });
    // });
      const weatherUrl = `${(window as any).environment.baseUrl}weather/info`;

      this.iframeSrc = this.sanitizer.bypassSecurityTrustResourceUrl('http://www.nmc.cn/publish/forecast/ANX/zhongwei.html');
      this.fetchService.post<any>(weatherUrl, {}).subscribe(res => {
            this.weatherInfo = res['info'];
            this.temperatureInfo = res['temperature'];
      });
  }

  onCancel(): void {
    this.modalShow = false;
  }

  onQxCancel(): void {
    this.qxModalShow = false;
  }

  onClickNav(fullUrl) {
    window.open(fullUrl);
  }
}
